﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Capa_Entidad;
namespace Acceso_Datos.Clases_DAO
{
    public class clsAte_Atencion_DiagnosticoDAO
    {
        private BDClinicaEntities ContextoDeObjs = new BDClinicaEntities();

        public bool Insertar(ATE_ATENCION_DIAGNOSTICO Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("ATE_ATENCION_DIAGNOSTICO", Obj);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool Modificar(ATE_ATENCION_DIAGNOSTICO obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("ATE_ATENCION_DIAGNOSTICO", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;

            }
        }

        public bool Eliminar(ATE_ATENCION_DIAGNOSTICO obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("ATE_ATENCION_DIAGNOSTICO", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public int ObtenerIdUltimo() {
            int IdDiagnostico = 0;
            try
            {
               
                var q = (from a in ContextoDeObjs.ATE_ATENCION_DIAGNOSTICO
                         select a.ATD_ID_DIAGNOSTICO).DefaultIfEmpty(0).Max();

                IdDiagnostico = Convert.ToInt16(q) + 1;
                return IdDiagnostico;
            }
            catch (Exception)
            { 
            return IdDiagnostico ;
            
            }
        }

       
    }
}
